<template>
	<view>
		
	</view>
</template>

<script>
	export default {
		components:{
			
		},
		data() {
			return {
				rightText: '我要申诉',
				title: "待收款",
				payType:'',
				payTypeId:0,
				userId:'',
				info: {
					"id": 80021,
					"type": "buy",
					"account_type": "zy",
					"order_no": "3564761052202681",
					"buy_id": 35,
					"sell_id": 38,
					"num": 10,
					"unit_price": "1.20",
					"total_price": "12.00",
					"ratio_money": "0.50",
					"collection_id": 1294,
					"cancel_num": 0,
					"appeal_data": null,
					"image": null,
					"sell_pay_time": "2023-06-04 17:15:33",
					"buy_pay_time": null,
					"confirm_sk_time": null,
					"date_num": 20230604,
					"is_finish": 0,
					"status": 1,
					"remark": null,
					"add_time": 1685809680,
					"sell_collections": [{
							"id": 1294,
							"user_id": 38,
							"type": "bank",
							"network": null,
							"data": {
								"real_name": "刘小超",
								"bank_number": "54569874563214560",
								"bank_name": "农业硬行"
							},
							"add_time": 1685709686
						},
						{
							"id": 1295,
							"user_id": 38,
							"type": "ysf",
							"network": null,
							"data": {
								"real_name": "刘小超",
								"phone": "13594335474"
							},
							"add_time": 1685709819
						},
						{
							"id": 1296,
							"user_id": 38,
							"type": "usdt",
							"network": "trc",
							"data": {
								"network": "trc",
								"money_address": "2ae4eec4790e3610c27329651a478db9",
								"image": ""
							},
							"add_time": 1685709866
						},
						{
							"id": 1297,
							"user_id": 38,
							"type": "usdt",
							"network": "trc2",
							"data": {
								"network": "trc2",
								"money_address": "2ae4eec4790e3610c27329651a478d00",
								"image": ""
							},
							"add_time": 1685709875
						},
						{
							"id": 1298,
							"user_id": 38,
							"type": "wechat",
							"network": null,
							"data": {
								"real_name": "刘小超",
								"account_name": "13594335474",
								"image": ""
							},
							"add_time": 1685711484
						},
						{
							"id": 1299,
							"user_id": 38,
							"type": "alipay",
							"network": null,
							"data": {
								"real_name": "刘小超",
								"account_name": "13594335474",
								"image": ""
							},
							"add_time": 1685711503
						}
					],
					"order_end_time": 1686114887,
					"buy_info": {
						"id": 35,
						"nickname": "多大点事",
						"mobile": "18681496382"
					},
					"sell_info": {
						"id": 38,
						"nickname": "135****5411",
						"mobile": "13594335412"
					},
					"buy_collection": {
						"id": 1294,
						"type": "bank",
						"network": null,
						"data": { //这个好像是json，在JSON.parse以下
							"real_name": "刘小超",
							"bank_number": "54569874563214560",
							"bank_name": "农业硬行"
						}
					},
					"count_trade_inf": {
						"finish_num": 95,
						"finish_raio": 48
					}
				},
				isImage:0,//是否需要跳转相册
			}
		},
		onLoad(opt) {
			var id = opt.id
			 this.userId = opt.userId
			var that = this
			this.api.http.requests('exchange/detail', {
				id: id
			}, res => {
				console.log(res)
				if (res.data) {
					that.info = res.data
					if(that.info.status == 2 || that.info.status == 3){
						that.rightText = '我要申诉'
					}else {
						that.rightText =''
					}
					// that.order_end_time = that.getTimesTamp(that.info.order_end_time) 
				}

			}, "POST")
		},
		onShow() {
			if(this.isImage == 3){
				this.isImage = 0
				var that = this
				setTimeout(function () {
				    //要延时执行的代码
				   that.uploadImg()
				}, 100) //延迟时间 
				
			}
		},
		methods: {
			getStautsStyle(item){
				if(item.status == 1 ){
					// if(item.sell_id == this.userId){
					// 	return "待买家付款"
					// }
					// return "待付款"
				}else if(item.status == 2){
					// if(item.sell_id == this.userId){
					// 	return "待收款"
					// }
					// return "待商家确认"
				}else if(item.status == 3){
					return "background-color:#D1D1D1"
				}else if(item.status == 4){
					return "background-color:#D1D1D1"
				}else if(item.status == -1){
					return 'background-color:#D1D1D1'
				}
			},
			clickLeft() {
				uni.navigateBack()
			},
			clickRight() {
				uni.navigateTo({
					url: '../../pages/my/appeal?id=' + this.info.id
				})
			},
			uploadImg() {
				if(this.info.status == 0)
					return	
				if(this.info.status == 3 || this.userId == this.info.sell_id || this.info.status == 4){
					if(this.info.image){
						uni.previewImage({
							urls:[this.getPayImage(this.info.image)]
						})
					}
					
					return
				}
				
				let that = this
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						that.http.upload(tempFilePaths[0], {}, res => {
							that.info.image = ''+res.data
						})

					}
				});

			},
			getTimesTamp(time){
				if(time * 1000 > new Date().getTime()){
					return true //未超时
				}
				return false
			},
			getStauts(item) {
				
				if(item.status == 1 ){
					if(!this.getTimesTamp(item.order_end_time)){
						return "订单已超时"
					}
					if(item.sell_id == this.userId){
						return "待买家付款"
					}
					return "提交付款"
				}else if(item.status == 2){
					if(!this.getTimesTamp(item.order_end_time)){
						return "订单已超时"
					}
					if(item.sell_id == this.userId){
						return "确认发货"
					}
					return "待商家确认"
				}else if(item.status == 3){
					return "申述中"
				}else if(item.status == 4){
					if(item.sell_id == this.userId){
						return "已完成收款"
					}
					return "已完成"
				}else if(item.status == -1){
					return '该订单已取消'
				}
			},
			getPayImage(url){
				var baseUrl = ''
				if(url && url.startsWith(baseUrl)){
					return url
				}else if(url && !url.startsWith(baseUrl)){
					return baseUrl+url 
				}else{
					return '../../static/my/oreder_tu.png'
				}
				
			},
			selectPay(sell_collections){
				if(this.info.status == 0)
					return	
				if(this.info.status == 3 || this.userId == this.info.sell_id || this.info.status == 4){
					if(this.info.image){
						uni.previewImage({
							urls:[this.getPayImage(this.info.image)]
						})
					}
					return
				}
				
				if(sell_collections == 0 &&  this.info.buy_collection){
					this.uploadImg()
					return
				}else if(sell_collections == 0 &&  !this.info.buy_collection){
					sell_collections =this.info.sell_collections
					this.isImage = 3
				}
				if(this.info.status == 1){
					this.$refs.payList.open(1,sell_collections)
				}
			},
			selectPayCall(data){
				// this.payType = data.type
				// this.payTypeId = data.id
				
				this.info.buy_collection = data
				uni.navigateTo({
					url: '../../pages/my/payInfo?data='+JSON.stringify(data)
				})
				
			},
			submit(){
				console.log('11111111111')
				if(!this.getTimesTamp(this.info.order_end_time)){
					uni.showToast({
						title:"订单已超时",
						icon:'none'
					})
					return 
				}
				var url= ''
				var data={}
				var msg = "提交成功"
				if(this.info.status == 3 || this.info.status == 4)
					return
				if(this.info.sell_id == this.userId){
					if(this.info.account_type == 'zy' && !this.info.image){
						return
					}
					url = 'exchange/confirm'
					data.id = this.info.id
					msg ='确认收款成功'
				}else {
					
					if(this.info.account_type == 'zy' && !this.info.image){
						uni.showToast({
							title:'请上传支付凭证',
							icon:'none'
						})
						return
					}
					url = 'exchange/payment'
					data.id = this.info.id
					data.collection_id = this.info.buy_collection.id
					if(this.info.account_type == 'zy'){
						data.image = this.info.image.replace('','')//llwg.qufeiya.cn
					}
				}
				// console.log(111,this.info.image)
				this.api.http.requests(url, data, res => {
					// uni.showToast({
					// 	title:msg,
					// 	icon:'none'
					// })
					uni.showToast({
						title: msg,
						success: function() {
							setTimeout(function() {
								//要延时执行的代码
								uni.navigateBack()
							}, 3000) //延迟时间 
						}
					})
					
				
				}, "POST")
				
			}

		}
	}
</script>

<style lang="less">
	page {
		background-color: white;
	}

	.uni-navbar {
		.uni-navbar__content {
			border: 0 none !important;
		}

		.uni-nav-bar-right-text {
			font-size: 14px;
		}
	}

	// .bar{
	// 	font-size: 30px;
	// }

	.black_1 {
		font-size: 56rpx;
		font-weight: 800;
		color: #5878E8;
		text-align: center;
		margin-top: 50px;
	}

	.black_2 {
		font-size: 25rpx;
		font-weight: 400;
		color: #666666;
		text-align: center;
		margin-top: 5px;

		.text1 {
			color: #5878E8;
		}
	}

	.black_3 {
		margin: 10px;
		background: #F3F5F7;
		border-radius: 18rpx;
		border-radius: 5px;
		padding: 10px;

		.label_1 {
			padding: 5px 0px;
			font-size: 28rpx;
			font-weight: bold;
			color: #1C1C1C;
		}

		.label_2 {
			font-size: 28rpx;
			font-weight: 400;
			color: #666666;
			display: flex;
			justify-content: space-between;
			padding: 5px 0px;

			.right {
				color: #666666;
				text-align: end;
				.text1{
					margin: auto 0px auto auto;
				}
				.img {
					width: 20px;
					height: 20px;
				}
			}

			.price {
				color: #FC4F3D;
			}

			.tiem {
				color: #666666;

			}

			.name {
				color: #1C1C1C;
			}

		}

		.label_3 {
			font-size: 28rpx;
			font-weight: bold;
			color: #1C1C1C;
		}

		.pay_tu {
			margin-top: 10px;
			width: 100px;
			height: 100px;
		}

	}

	.bottom {
		position: fixed;
		bottom: 10px;
		width: 100%;

		.label_1 {
			padding: 10px 20px;
			display: flex;
			justify-content: space-between;
			align-items: center;
			justify-items: center;

			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;
				
				.text1 {
					display: flex;
					
					// color: #5878E8;
				}
			}

			.right {
				background-color: #5878E8;
				border-radius: 5px;
				padding: 8px 25px;
				text-align: center;
				font-size: 35rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}
</style>